//
//  FunctionView.m
//  Contacts
//
//  Created by 李 雷川 on 14-7-15.
//  Copyright (c) 2014年 李 雷川. All rights reserved.
//

#import "FunctionView.h"

@implementation FunctionView
@synthesize functionBtn,functionNameLabel;
@synthesize function;
@synthesize enterBlock;
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        CGRect frame =CGRectMake(5,11,74,74);
        functionBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        functionBtn.frame = frame;
        [functionBtn addTarget:self action:@selector(enterFunctionController:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:functionBtn];
        
        functionNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(0,CGRectGetMaxY(functionBtn.frame),CGRectGetWidth(self.frame),12)];
        functionNameLabel.textAlignment = NSTextAlignmentCenter;
        functionNameLabel.backgroundColor = [UIColor clearColor];
        functionNameLabel.font = [UIFont systemFontOfSize:12];
        [self addSubview:functionNameLabel];
    }
    return self;
}

-(void)initWithFuntion:(Funtion *)_funtion{
    self.function = _funtion;
    UIImage *image = nil;
    switch (function.type) {
        case 0:
            image = [UIImage imageNamed:@"notice.png"];
            break;
        case 1:
            image = [UIImage imageNamed:@"contact.png"];
            break;
        case 2:
             image = [UIImage imageNamed:@"more.png"];
            break;
        default:
            break;
    }
    [functionBtn setImage:image forState:UIControlStateNormal];
    functionNameLabel.text = function.name;
}

-(void)enterFunctionController:(id)sender{
    if (self.enterBlock) {
        self.enterBlock();
    }
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
